package yagwl.client.model;

import com.google.gwt.event.shared.EventHandler;
import com.google.gwt.event.shared.GwtEvent;

/**
 * Represents the event that is raised when an asynchronous RPI involving data
 * manipulation is completed. Data manipulation includes data fetch from server,
 * delete, update, etc.
 */
public class MasterDetailEvent extends GwtEvent<MasterDetailEvent.MasterDetailEventHandler> {

  public static final Type<MasterDetailEventHandler> TYPE = new Type<MasterDetailEventHandler>();
  private String objectName;
  private EventType eventType;
  
  public enum EventType {
    LoadSuccess, MasterItemCreated
  }

  MasterDetailEvent(String objectName, EventType eventType) {
    super();
    this.objectName = objectName;
    this.eventType = eventType;
  }

  public String getObjectName() {
    return objectName;
  }

  public EventType getEventType() {
    return eventType;
  }

  @Override
  protected void dispatch(MasterDetailEventHandler handler) {
    handler.onMasterDetailEvent(this);
  }

  @Override
  public GwtEvent.Type<MasterDetailEventHandler> getAssociatedType() {
    return TYPE;
  }

  /**
   * Widgets interested in ItemListEvent must implement this interface.
   */
  public interface MasterDetailEventHandler extends EventHandler {
    public void onMasterDetailEvent(MasterDetailEvent event);
  }
}
